$.extend({

addError: function (element, msg) {
	var error = $(element).next('span[class="error"]');
	if( error.size()==0 ) {
		$(element).after('<span class="error">'+msg+'</span>');
	} else {
		error.html(msg);
	}
		
},	
	
removeError: function (element) {
	$(element).next('span[class="error"]').remove();
},

checkRequired: function(element) {
	if ($(element).val() == '') {
		return false;
	} else {
		return true;
	}
},

checkAllRequired : function(selector) {

	var validated = true;

	$(selector).find('[required]').each(function(index) {
		if(!$.checkRequired(this)) {
			$.addError(this,'required');
			validated = false;
		} else {
			$.removeError(this);
		}
	});

	return validated;
}

});